package com.tianma315.admin.qa.controller;


import java.util.Arrays;
import java.util.Date;

import com.tianma315.admin.common.base.BaseController;
import com.tianma315.admin.common.utils.Result;
import com.tianma315.admin.qa.vo.QaSpotCheckVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.qa.domain.QaSpotCheckDO;
import com.tianma315.admin.qa.service.QaSpotCheckService;

/**
 * 
 * <pre>
 * 品控抽查
 * </pre>
 * <small> 2019-07-09 16:02:56 | wen</small>
 */
@Controller
@RequestMapping("/qa/qaSpotCheck")
public class QaSpotCheckController extends BaseController {
	@Autowired
	private QaSpotCheckService qaSpotCheckService;
	
	@GetMapping()
	@RequiresPermissions("qa:qaSpotCheck:qaSpotCheck")
	String QaSpotCheck(){
	    return "qa/qaSpotCheck/qaSpotCheck";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("qa:qaSpotCheck:qaSpotCheck")
	public Result<Page<QaSpotCheckVO>> list(Integer pageNumber, Integer pageSize, QaSpotCheckDO qaSpotCheckDTO, Date beginDate,
											Date endDate){
		// 查询列表数据
        Page<QaSpotCheckVO> page = qaSpotCheckService.getQaSpotCheckPage(pageNumber,pageSize,qaSpotCheckDTO,beginDate,endDate);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("qa:qaSpotCheck:add")
	String add(){
	    return "qa/qaSpotCheck/add";
	}

	@GetMapping("/edit/{qaSpotCheckId}")
	@RequiresPermissions("qa:qaSpotCheck:edit")
	String edit(@PathVariable("qaSpotCheckId") Integer qaSpotCheckId,Model model){
		QaSpotCheckDO qaSpotCheck = qaSpotCheckService.selectById(qaSpotCheckId);
		model.addAttribute("qaSpotCheck", qaSpotCheck);
	    return "qa/qaSpotCheck/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("qa:qaSpotCheck:add")
	public Result<String> save( QaSpotCheckDO qaSpotCheck){
		qaSpotCheck.setCreateBy(getUserId());
		qaSpotCheck.setCheckBy(getUserId());
		if(qaSpotCheckService.addQaSpotCheck(qaSpotCheck)){
			return Result.ok();
		}
		return Result.fail();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("qa:qaSpotCheck:edit")
	public Result<String>  update( QaSpotCheckDO qaSpotCheck){
		qaSpotCheckService.updateById(qaSpotCheck);
		return Result.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("qa:qaSpotCheck:remove")
	public Result<String>  remove( Integer qaSpotCheckId){
		if(qaSpotCheckService.deleteQaSpotCheck(qaSpotCheckId)){
            return Result.ok();
		}
		return Result.fail();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("qa:qaSpotCheck:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Integer[] qaSpotCheckIds){
		for (Integer id:qaSpotCheckIds) {
			qaSpotCheckService.deleteQaSpotCheck(id);
		}
		return Result.ok();
	}
	
}
